// $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.alwaysOverridetoString.alwaysOverrideToString, spellCheckIdentifiers
/**
 * Package logging
 */
package teamrocket.logging; // $codepro.audit.disable packagePrefixNamingConvention

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

/**
 * Class TLogger. 
 * @author Stephen Tapper
 * @version 1.0
 */
public class TLogger {

	/**
	 * Field INSTANCE.
	 */
	private static final TLogger INSTANCE = new TLogger();

	/**
	 * Field myLogger.
	 */
	private Logger myLogger = Logger.getLogger("teamrocket.logging.Logger"); // $codepro.audit.disable nonStaticLogger, variableShouldBeFinal

	/**
	 * Constructor for TLogger.
	 */
	private TLogger(){
		FileHandler fh = null;
        try {
            fh = new FileHandler("application.log");
            //myLogger.log(Level.SEVERE, "brick");
        } catch (SecurityException e) {
            myLogger.log(Level.SEVERE,
            		"Security Exception creating the logger file handler");
            e.printStackTrace();
        } catch (IOException e) {
            myLogger.log(Level.SEVERE, "IO Exception creating the logger file handler");
            e.printStackTrace();
        }
        
        fh.setFilter( new Filter() { // $codepro.audit.disable nullPointerDereference
            public boolean isLoggable(LogRecord record) {
                //we would put whatever logic we need in here to 
                //determine if this should be logged.
                //for demo purposes, I am putting true
                return true;
            }
        });
        myLogger.addHandler(fh);
        myLogger.setLevel(Level.ALL);
        
	}
	
	/**
	 * Gets the singleton TLogger instance
	
	 * @return TLogger
	 */
	public static TLogger getInstance(){
		return INSTANCE;
	}
	
	/**
	 * Returns the logger for this class
	
	 * @return Logger
	 */
	public Logger getLogger() {
		return myLogger;
	}
}
